package com.inxedu.os.edu.controller.course;

import com.inxedu.os.edu.pojo.EduWebsiteCourse;
import com.inxedu.os.edu.service.course.AdminWebSiteCourse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
public class AdminWebsiteCourseController {
//    @InitBinder("websiteCourse")
//    public void initBinderWebsiteCourse(WebDataBinder binder) {
//        binder.setFieldDefaultPrefix("websiteCourse.");
//    }
    @Autowired
    private AdminWebSiteCourse webSiteCourse;
    //查询推荐课程分类
    @RequestMapping("/admin/website/websiteCoursePage")
    public String toWebsiteCourse(Model model,EduWebsiteCourse websiteCourse){
        List<EduWebsiteCourse> select =webSiteCourse.select(websiteCourse);
        model.addAttribute("websiteCourseList",select);
        return "view/inxedu/admin/website/course/websiteCourse_list";
    }

    //添加
    @RequestMapping("/admin/website/doAddWebsiteCourse")
    public String toAddWebsiteCourse(Model model,@ModelAttribute("eduWebsiteCourse") EduWebsiteCourse eduWebsiteCourse){


        return "view/inxedu/admin/website/course/websiteCourse_add";
    }
    @RequestMapping("/admin/website/addCourse")
    public String AddWebsiteCourse(Model model,EduWebsiteCourse eduWebsiteCourse){
        int i = webSiteCourse.insetEduWebsiteCourse(eduWebsiteCourse);
        model.addAttribute("websiteCourse",i);
        return "redirect:/admin/website/websiteCoursePage";
    }

    //初始化修改页面
    @RequestMapping("/admin/website/doUpdateWebsiteCourse/{id}")
        public String updateWebsiteCourse(Model model,@PathVariable("id")int id){
            EduWebsiteCourse eduWebsiteCourse = webSiteCourse.selectAll(id);
            System.out.println(eduWebsiteCourse);
            model.addAttribute("websiteCourse",eduWebsiteCourse);
            return "view/inxedu/admin/website/course/websiteCourse_update";
    }
    //修改
    @RequestMapping("/admin/website/updateWebsiteCourse")
    public String update(EduWebsiteCourse course){
        webSiteCourse.update(course);
        return "redirect:/admin/website/websiteCoursePage";
    }
    //删除
    @RequestMapping("/admin/website/delWebsiteCourseById/{id}")
    public String delete(@PathVariable("id")Integer id){
        int delete = webSiteCourse.delete(id);
        return "redirect:/admin/website/websiteCoursePage";
    }
}
